
<?
	  layout("/inc/win_layout.html",{title:sysTitle}){
    ?>

<div class="row">
	<div class="col-lg-12">
		<div class="panel ">
			<div class="panel-body pan">
				<form action="#" class="form-horizontal">
					<div class="form-body pal" style="width:320px; height: 390px">

						<div
							style="width:300px; margin:0 30px 0 80px; padding-bottom:10px; ">
							<label for="inputUsername" class="col-md-3 control-label">字典项中文名称
								<span class='require' id="zhongwenName">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="nameZh" type="text" class="form-control" value="" onchange="pinYin(this.value)" />
								</div>
							</div>
						</div>


						<div
							style="width:300px; margin:0 30px 0 80px;padding-bottom: 10px;">
							<label for="inputUsername" class="col-md-3 control-label">字典项英文名称
								<span class='require' id="yingwenName">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="nameEn" type="text" class="form-control" />
								</div>
							</div>
						</div>

						<div
							style="width:300px; margin:0 30px 0 80px;padding-bottom: 10px;">
							<label for="inputUsername" class="col-md-3 control-label">字典项值
								<span class='require' id="yingwenName">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="value" type="text" class="form-control" />
								</div>
							</div>
						</div>

						<div
							style="width:300px; margin:0 30px 0 80px;padding-bottom: 10px;">
							<label for="inputUsername" class="col-md-3 control-label">排序
								<span class='require' id="paixu">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="sort" type="text" class="form-control" />
								</div>
							</div>
						</div>
						<div
							style="width:300px; margin:0 30px 0 80px;padding-bottom: 10px;">
							<label for="inputUsername" class="col-md-3 control-label">父节点
								<span class='require' id="paixu"></span> </label>
							<div class="col-md-9">
								<div class="input-group input-group-sm mbs">
									<input id="dictitemName" type="text" placeholder="根目录"
										class="form-control" disabled="true" /> <span
										class="input-group-btn"><button id="xuanze"
											onclick="saveEditZTree()" type="button"
											data-toggle="dropdown"
											class="btn btn-success dropdown-toggle">选择类..</button>
									</span>
									<!-- <input id="dictItem" type="text" class="form-control" /> -->
								</div>
							</div>
						</div>
						<input id="id" type="hidden" class="form-control" /> <input
							id="dictId" type="hidden" class="form-control" /> <input
							id="dictitemId" type="hidden" class="form-control" value="0" />
						<!--<div class="col-md-9" style="width:300px;">
							<label for="inputUsername" class="col-md-3 control-label">
							<span class='require' ></span> </label>
							 
							<div class="input-icon">
								<button type="submit" onclick="Page()" class="btn btn-primary"id="submit">
									提交
								</button>&nbsp;&nbsp;&nbsp;
								
							</div>
						</div> -->
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<?} ?>
<!-- 
<iframe name="child" src="dictItem-save-edit-findall-zTree.html" id="ifr" style="HEIGHT: 10px; LEFT: 0px; POSITION: absolute;  WIDTH: 0px"></iframe>
 -->
<script>
	var index1 = window.parent.getaddupate();
	var treeNode = window.parent.gettreeNode();
	var dictId = window.parent.getDictId();
	var pName = window.parent.getclassname();
	var dictitemId = window.parent.getclassid();
	var sum = window.parent.getsum();
	var sortsum = window.parent.getsortsum();
	
	//$("#id").val(index1);
	$("#dictId").val(dictId);
	//$("#sort").val(sum);
	/* if(sortsum == '-1'){
		if(sum<10){
			$("#value").val("0"+sum);
		}else{
			$("#value").val(sum);
		}
		
	}else{
		var temporary;
		if(sum<10){
			$("#value").val(sortsum+".0"+sum);
		}else{
			$("#value").val(sortsum+"."+sum);
		}
		
	} */
	
	

/*	function get() {
		demo1(curr);
	}*/

	$(function() {
		if (index1 != 0) {
			demo1(index1);
		}else{
			$("#dictitemName").val(pName);
			$("#dictitemId").val(dictitemId);
			dictValue();
		}
	});

	function getdictIdZTree() {
		return dictId;
	}
	function saveEditZTree() {
		parent.layer.open({
			type : 2,
			area : [ '510px', '500px' ],
			fix : false, //不固定
			//maxmin : true,
			scrollbar : false,
			shadeClose : true,
			title : '字典项管理',
			btn : [ '保存 ', '关闭' ],
			skin : 'layui-layer-rim', //加上边框
			content : ["dictItem-save-edit-findall-zTree.html?winName="+window.name,'no'],
			yes : function(index, layer) {
				//alert(index);
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				//alert(iframeWin);
				iframeWin.queren();
			},
			cancel : function(index) {
			}
		});
	};

	function Page() {
	
		if ($.trim($("#nameEn").val()).length < 1) {
			alert('英文名称不能为空！');
			return null;
		}
		if ($.trim($("#nameZh").val()).length < 1) {
			alert('中文名称不能为空！');
			return null;
		}
		if ($.trim($("#value").val()).length < 1) {
			alert('数据类型不能为空！');
			return null;
		}
		if ($.trim($("#sort").val()).length < 1) {
			alert('排序不能为空！');
			return null;
		}
		if (isNaN($("#sort").val())) {
			alert("必须是数字");
			return null;
		}
		$.ajax({
			type : "post",
			url : "./dictItemAddandUpdate.do",
			data : {
				"id" : $("#id").val(),
				"dictId" : $("#dictId").val(),
				"nameZh" : $("#nameZh").val(),
				"nameEn" : $("#nameEn").val(),
				"value" : $("#value").val(),
				"sort" : $("#sort").val(),
				"dictItemId" : $("#dictitemId").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				/* window.parent.initTree(); */
				/* window.parent.loadOneTree(); */
				if ($("#dictitemId").val() != 0) {
					//window.parent.refreshParentNode();
					window.parent.showTree(data,treeNode);
				}else{
					//window.parent.showTree(data,treeNode);
					//window.parent.refreshNode();
					window.parent.loadOneTree();
				}
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}

	function demo1(dictItemid) {
		$.ajax({
			type : "post",
			url : "./dictItmefindone.do",
			data : {
				"id" :dictItemid
			},
			dataType : "json",
			success : function(res) {
				$("#id").val(res[0].id);
				$("#nameZh").val(res[0].nameZh);
				$("#nameEn").val(res[0].nameEn);
				$("#value").val(res[0].value);
				$("#sort").val(res[0].sort);
				$("#dictitemName").val(res[0].dictitemName);
				$("#dictitemId").val(res[0].dictitemId);
			},
			error : function(res) {
				alert("请求失败");
			}
		});
	};
	function shuaxin() {
		$("#dictitemId").val("0");
		$("#nameZh").val("");
		$("#nameEn").val("");
		$("#value").val("");
		$("#sort").val("");
		$("#dictitemName").val("");
	}
	
	//汉字转拼音
  function pinYin(pinyinName){
		$.ajax({
			type : "post",
			url : "pinYin.do",
			data : {
				"pinYin" : pinyinName,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data[0].length > 32){
					layer.msg('自动转换英文名长度过长!请手动输入！');
					$("#nameEn").val("");
				}else{
					$("#nameEn").val(data);
				}	
			},
			error : function(data) {
				alert("请求失败");
			}
		})
	}
	//自动字典项值
  function dictValue(){
  		var itemIds = $("#dictitemId").val();
		$.ajax({
			type : "post",
			url : "dictValue.do",
			data : {
				"dictId" : dictId,
				"dictItemId" : itemIds,
			},
			dataType : "json",
			success : function(data) {
				$("#value").val(data[0].value);
				$("#sort").val(data[0].sort);
			},
			error : function(data) {
				alert("请求失败");
			}
		})
	}
</script>


